package PVZ;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
//实现动态图:新启动一个线程实现换图
public class Z {
    private int Blood;
    private void skill(){
        if(Blood>0){
            //产生僵尸
            //如果前方有植物，攻击植物
        }
        //产生僵尸尸体，2s后清除僵尸
    }
}
class SetZ implements Runnable {
    public int Blood;
    public int x,y,type;
    public Boolean ifDie=true;
    public SetZ(int x,int y,int type){
        this.x=x;
        this.y=y;
        this.type=type;
        if(type==1){
            Blood=50;
        }
        if(type==2){
            Blood=100;
        }
        if(type==3){
            Blood=150;
        }
        //启动换图线程

    }
    public void run(){
        int re=0;
        while (Game.ifGame){
        if(Blood>0) {
           /* if (type == 1) {
                try {
                    Game.Pictrue1.Z1 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z1.png"));
                    Game.Pictrue1.Z1t=ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z1attack.png"));
                    Game.Pictrue1.Zd=ImageIO.read(new )
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (type == 2) {
                try {
                    Game.Pictrue1.Z2 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z2.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (type == 3) {
                try {
                    Game.Pictrue1.Z3 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z3.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {if(Game.ifZ0[x][y]==2) {
                if (type == 1) {
                    Game.Pictrue1.Z1 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z1attack.png"));
                } else if (type == 2) {
                    Game.Pictrue1.Z2 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z2attack.png"));
                } else if (type == 3) {
                    Game.Pictrue1.Z3 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z3attack.png"));
                }
            }
            } catch (IOException e) {
                e.printStackTrace();
            }*/
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (; x > 20;) {
                if(Game.ifplants[x][y]==0){
                Game.ifZ0[x][y]=1;}else {
                    Game.ifZ0[x][y]=2;
                }//被植物挡住的僵尸不可删除？？
                Game.p1.DrawZ(x, y, type,re);
                re++;
                //Game.p1.repaint();
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if(Game.ifPeas[x][y]==1&&x<1500){
                    Blood--;
                    Game.ifPeas[x][y]=0;
                }
                if(Blood<=0){
                    Game.ifZ0[x][y]=3;
                    Game.Ztype[x][y]=99;
                    //Game.p1.DrawZ(x, y, type,-1);
                    break;
                }
                if(Game.ifplants[x][y]==0){
                    Game.ifZ0[x][y]=0;
                    x = x - 1;
                }/*else {Game.ifZ0[x][y]=2;
                        /*try {if(Game.ifZ0[x][y]==1) {
                            if (type == 1) {
                                Game.Pictrue1.Z1 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z1attack.png"));
                            } else if (type == 2) {
                                Game.Pictrue1.Z2 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z2attack.png"));
                            } else if (type == 3) {
                                Game.Pictrue1.Z3 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Z3attack.png"));
                            }
                        }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }*/

            }
            if (Blood <= 0) {Game.ifZ0[x][y]=3;
                while (ifDie) {
                    Game.Ztype[x][y]=99;
                    //Game.p1.DrawZ(x, y, type,1);
                    //Game.p1.repaint();
                }}//僵尸死亡
                /*try {if(Game.ifZ0[x][y]==0) {
                    if (type == 1) {
                        Game.Pictrue1.Z1 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Zdie.png"));
                        while (ifDie) {
                            Game.p1.DrawZ(x, y, 1);
                            Game.p1.repaint();
                        }
                    } else if (type == 2) {
                        Game.Pictrue1.Z2 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Zdie.png"));
                        while (ifDie) {
                            Game.p1.DrawZ(x, y, 2);
                            Game.p1.repaint();
                        }
                    } else if (type == 3) {
                        Game.Pictrue1.Z3 = ImageIO.read(new File("D:\\Morven\\IdeaProjects\\PVZ\\picture\\Zombies\\Zdie.png"));
                        while (ifDie) {
                            Game.p1.DrawZ(x, y, 3);
                            Game.p1.repaint();
                        }
                    }
                }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }*/
        }
    }}
}
//普通僵尸
class Z1 extends Z{
    //public int Blood;
    public Z1(){
    }
    public Z1(int x,int y){
        skill(x,y);
    }
    private void skill(int x,int y){
        SetZ z=new SetZ(x,y,1);
        Game.ifZ0[x][y]=1;
        Thread thread2=new Thread(z);
        thread2.start();
        /*RePicture rp1=new RePicture(1);
        Thread thread01=new Thread(rp1);
        thread01.start();*/
    }
}
//路障僵尸
class Z2 extends Z{
    public int Blood=20;
    public Z2(){
    }
    public Z2(int x,int y){
        skill(x,y);
    }
    private void skill(int x,int y){
        SetZ z=new SetZ(x,y,2);
        Game.ifZ0[x][y]=1;
        Thread thread2=new Thread(z);
        thread2.start();
        /*RePicture rp2=new RePicture(2);
        Thread thread02=new Thread(rp2);
        thread02.start();*/
    }
}
//铁桶僵尸
class Z3 extends Z{
    public int Blood=50;
    public Z3(){
    }
    public Z3(int x,int y){
        skill(x,y);
    }
    private void skill(int x,int y){
        SetZ z=new SetZ(x,y,3);
        Game.ifZ0[x][y]=1;
        Thread thread2=new Thread(z);
        thread2.start();
        /*RePicture rp3=new RePicture(3);
        Thread thread03=new Thread(rp3);
        thread03.start();*/
    }
}
